package com.zy.fcs.controller;

import com.alibaba.fastjson.JSONArray;
import com.zy.fcs.bean.LoginInfo;
import com.zy.fcs.service.ZtreeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 登陆Controller
 *
 * @author zhanghengchang
 * @date 2018/3/6
 */
@Controller
public class LoginController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private ZtreeService ztreeService;

    @PostMapping(value = "/login")
    public String login(Model model, @ModelAttribute LoginInfo loginInfo, HttpSession session) throws Exception {

        // 机构号
        String instNo = loginInfo.getInstNo();

        // 树形结构JSON
        JSONArray treeJson = ztreeService.getTreeJson(instNo, "");
        model.addAttribute("treeJson", treeJson);
        model.addAttribute("mediaType", "index");
        model.addAttribute("applNo", "");
        model.addAttribute("instNo", "");

        // 登陆信息添加到Session
        session.setAttribute("loginInfo", loginInfo);

        return this.render("index");
    }
}
